﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>验证表单项必须填写</title>
    <script type="text/javascript" language="JavaScript">
        function CheckForm(){
            // 判断输入框内容的长度
            if(document.getElementById("txtname").value.length === 0){
                alert("姓名必须输入");
                document.getElementById("txtname").focus();
                return false;
            }
            return true;
        }
        
    </script>
</head>
<body>
请输入姓名：<input type=text name="txtname" value="" onblur="CheckForm()">
</body>
</html>